# -*- coding: utf-8 -*-#
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import pymysql

from pyspark.sql import SparkSession
from pyspark.ml.recommendation import ALSModel

pymysql.install_as_MySQLdb()

app = Flask(__name__)
app.secret_key = "recommend"

# 数据库连接
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:123456@localhost:3306/recommend"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)
# 创建SparkSession对象
spark = SparkSession.builder.appName("ALS").getOrCreate()

path = r"C:\alsmodel"

# 加载模型
model = ALSModel.load(path)

app.config["Spark"] = spark
app.config["Model"] = model
